﻿using Demo.WebApi.Context;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.AspNetCore;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;

namespace Demo.WebApi
{
    [DependsOn(typeof(AbpAspNetCoreModule)
        ,typeof(AbpAutofacModule)
        )]
    public class DemoWebApiModule:AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddControllers();
            context.Services.AddEndpointsApiExplorer();
            context.Services.AddSwaggerGen();
            var dbContext = context.Services.GetConfiguration();
            context.Services.AddDbContext<DemoWenApiContext>(options=>
            {
                options.UseSqlServer(dbContext.GetConnectionString("default"));
            });
        }

        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
           
            var app = context.GetApplicationBuilder();
            
            var env=context.GetEnvironment();
            if (env.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }
            app.UseHttpsRedirection();
            app.UseAuthorization();
        }
    }
}
